package com.smallframework.mvc;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.TypeVariable;

/**
 * Created by tan on 2017/6/28.
 */
public class DispatcherServlet extends HttpServlet {


	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		//找到对应的类和对应的方法来执行
		//暂时不支持 请求参数 直接作为函数参数
		RequestHandlerContainer requestHandlerContainer = (RequestHandlerContainer) getServletContext().getAttribute("requestHandlerContainer");

		try {
			requestHandlerContainer.dealRequest(req, resp);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private Object transfer(HttpServletRequest req, TypeVariable<Method> typeVariable) {
		String name = typeVariable.getName();
		String value = req.getParameter("name");
		//TODO value转换为  typeVariable的type
		typeVariable.getTypeName();
		return value;
	}
}
